package com.biz.primus.ms.coupon.api;

import com.biz.primus.model.coupon.vo.coupon.CouponVo;
import com.biz.primus.model.coupon.vo.coupon.UserCouponListVo;
import com.biz.primus.model.coupon.vo.coupon.request.CreateCouponReqVo;
import com.biz.primus.model.coupon.vo.coupon.request.GetCouponCutAmountReqVo;
import com.biz.primus.model.coupon.vo.coupon.request.GetOrderProductAvailableCouponReqVo;
import com.biz.primus.model.coupon.vo.coupon.request.UseCouponReqVo;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.coupon.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 优惠券Api Controller
 *
 * @author david-liu
 */
@Api(value = "/soa/coupon", description = "操作优惠券")
@RestController
@RequestMapping(value = "/soa/coupon")
public class CouponApiController extends BaseApiController {

    @Autowired
    private CouponService couponService;

    @ApiOperation(value = "领取优惠券")
    @PostMapping(value = "/createCoupon")
    public Boolean createCoupon(@ApiParam @RequestBody CreateCouponReqVo reqVo) {
        reqVo.validate();
        return couponService.createCoupon(reqVo);
    }

    @ApiOperation(value = "列出用户优惠券")
    @GetMapping(value = "/listUserCoupons")
    public UserCouponListVo listUserCoupons(@RequestParam(name = "memberId") Long userId) {
        return couponService.listUserCoupons(userId);
    }

    @ApiOperation(value = "获取订单商品可用优惠券")
    @PostMapping(value = "/getCoupon4OrderProducts")
    public List<CouponVo> getCoupon4OrderProducts(@RequestBody GetOrderProductAvailableCouponReqVo reqVo) {
        reqVo.validate();
        return couponService.getCoupons4OrderProducts(reqVo);
    }

    @ApiOperation(value = "获取优惠券减免金额")
    @PostMapping(value = "/getCouponCutAmount4OrderProducts")
    public Integer getCouponCutAmount4OrderProducts(@RequestBody GetCouponCutAmountReqVo reqVo) {
        reqVo.validate();
        return couponService.getCouponCutAmount4OrderProducts(reqVo);
    }

    @ApiOperation(value = "使用优惠券")
    @PostMapping(value = "/useCoupon4Order")
    public void useCoupon4Order(@RequestBody UseCouponReqVo reqVo) {
        reqVo.validate();
        couponService.useCoupon(reqVo);
    }
}
